package com.nsn.vs.sdm.component.svn.command;

import java.io.File;

import org.tmatesoft.svn.core.wc.SVNUpdateClient;

import com.nsn.vs.sdm.component.svn.SvnClientManager;
import com.nsn.vs.sdm.component.svn.event.UpdateEventHandler;
import com.nsn.vs.sdm.util.string.UtilString;

/**
 * Used for executing update repository operation.
 * 
 * Available properties from operation are:
 *  revisionProperty
 * 
 * @author Jeccy.Zhao
 
 */
public class SvnCommandUpdate extends SvnCommand 
{
	
	/**
	 * The local path
	 */
	private String path;
	
	/**
	 * The sole constructor
	 * 
	 * @param manager
	 *         the svn client manager
	 * @param path
	 *         the local path
	 */
	public SvnCommandUpdate(SvnClientManager manager, String path) 
	{
		super(manager);
		
		this.path = UtilString.revertUnicodeChars(path);
		
		// sets the event handler for checkout operations
		manager.getManager().getUpdateClient().setEventHandler(
				new UpdateEventHandler(this));
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.nsn.hzta.tcr.component.svn.Command#execute()
	 */
	@Override
	public long execute() throws Exception 
	{
		File filePath = new File(this.path);
		
		// Get the Update Client
		SVNUpdateClient client = this.svnClient.getManager().getUpdateClient();
		
		// Execute svn info
		return client.doUpdate(filePath, this.revision, this.depth, this.recursive, this.force);
	}

	@Override
	protected void validateAttributes() throws Exception 
	{
		
	}
}
